{include file="public/header" /}
<link rel="stylesheet" href="https://cache.amap.com/lbs/static/main1119.css" />
<style>
    .bbbmmm{
        margin-top: 330px;
    }
    #container{
        height: 350px;
    }
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑</h5>
                </div>
                <div class="ibox-content layui-form">
                    <div class="layui-row layui-col-space10 layui-form-item ">
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">客户公司：</label>
                            <div class="layui-input-block">
                                <input type="text" class="layui-input" lay-verify="required" value="{$data.s_com_name}" name="s_com_name">
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">联系人：</label>
                            <div class="layui-input-block">
                                <input type="text" class="layui-input" lay-verify="required" value="{$data.s_name}" name="s_name">
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">联系电话：</label>
                            <div class="layui-input-block">
                                <input type="text" class="layui-input" lay-verify="required" value="{$data.s_phone}" name="s_phone">
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">内部老师：</label>
                            <div class="layui-input-block">
                                <input type="text" class="layui-input" value="{$data.s_inside_name}" name="s_inside_name">
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">老师电话：</label>
                            <div class="layui-input-block">
                                <input type="text" class="layui-input" maxlength="11" value="{$data.s_inside_phone}" name="s_inside_phone">
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md12">
                            <label class="layui-form-label">地址：</label>
                            <div class="layui-input-inline">
                                <select name="s_sheng" lay-search="" id="province"  lay-filter="province">
                                    <option value="">---- 请选择省 ----</option>
                                    {foreach name="province" item="vo"}
                                    <option value="{$vo.district_id}" {$vo.district_id == $data.s_sheng ? 'selected' : ''}>{$vo.district}</option>
                                    {/foreach}
                                </select>
                            </div>

                            <div class="layui-input-inline">
                                <select name="s_shi" lay-search=""  id="city"  lay-filter="city">
                                    <option value="">---- 请选择市 ----</option>
                                    {foreach name='city' item='vo1'}
                                    <option value="{$vo1.district_id}" {$vo1.district_id == $data.s_shi ? 'selected' : ''}>{$vo1.district}</option>
                                    {/foreach}
                                </select>
                            </div>

                            <div class="layui-input-inline">
                                <select name="s_qu" lay-search=""  id="district"  lay-filter="district">
                                    <option value="">---- 请选择区 ----</option>
                                    {foreach name='district' item='vo2'}
                                    <option value="{$vo2.district_id}" {$vo2.district_id == $data.s_qu ? 'selected' : ''}>{$vo2.district}</option>
                                    {/foreach}
                                </select>
                            </div>

                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md10">
                            <label class="layui-form-label">详细地址：</label>
                            <div class="layui-input-block">
                                <input type="text" class="layui-input" lay-verify="required" maxlength="11" value="{$data.s_address}" name="s_address">
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">获取经纬度：</label>
                            <div class="layui-input-block">
                                <div id="container"></div>
                                <div id="myPageTop">
                                    <table>
                                        <tr>
                                            <td>
                                                <label>请输入关键字：</label>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <input id="tipinput" type="text" />
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 bbbmmm">
                            <label class="layui-form-label">经纬度值：</label>
                            <div class="layui-input-block">
                                <div class="one flex-wrap underLine">
                                    <input type="text" name="lonlat" id="lonlat" class="layui-input" lay-verify="required" value="{$data.s_lat},{$data.s_lon}" placeholder="请点击地图上的位置获取经纬度" readonly>
                                </div>
                            </div>
                        </div>
                        <input type="hidden" value="{$data.s_id}" name="s_id">
                        <input type="hidden" value="{$data.s_lat}" id="s_lat">
                        <input type="hidden" value="{$data.s_lon}" id="s_lon">
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="component-form-element">提交
                                </button>
                                <!--<button class="layui-btn layui-btn-primary" onclick="wk.layer_close('close')">关闭</button>-->
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
</body>
</html>
<script src="https://webapi.amap.com/maps?v=1.4.15&key=3e1efc9bcd502e8d0ded020ee743130c&plugin=AMap.Geocoder,AMap.Autocomplete,AMap.PlaceSearch"></script>
<script src="https://a.amap.com/jsapi_demos/static/demo-center/js/demoutils.js"></script>
<script type="text/javascript" src="https://cache.amap.com/lbs/static/addToolbar.js"></script>
<script type="text/javascript">
    layui.use(['form','upload','layedit'], function() {
        var form = layui.form;
        form.on('submit(component-form-element)', function (data) {
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('updateLocation')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        layer.msg(res.msg,{icon:1,time:1500,shade:0.1},function(index){
                            wk.layer_close();
                        })
                    } else {
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            })
        });
    });
</script>
<script type="text/javascript">

    /**
     * 地图加载
     * @type {AMap.Map}
     */
    var slat = $('#s_lat').val();
    var slon = $('#s_lon').val();
    var map = new AMap.Map("container", {
        resizeEnable: true,
        center: [slon, slat]
    });
    //标个点先
    addChoiseMark(slon,slat)
    //输入提示
    var autoOptions = {
        input: "tipinput"
    };
    var auto = new AMap.Autocomplete(autoOptions);
    var placeSearch = new AMap.PlaceSearch({
        map: map,
//        pageSize:1
    });
    //构造地点查询类
    AMap.event.addListener(auto, "select", select);//注册监听，当选中某条记录时会触发
    function select(e) {
        placeSearch.setCity(e.poi.adcode);
        placeSearch.search(e.poi.name);  //关键字查询查询
        //搜索结果一出来就先获取经纬度
//        var lng = e.poi.location.lng;   //获取经度
//        var lat = e.poi.location.lat;
//        document.getElementById("lonlat").value = lat + ',' + lng;
//        map.clearMap();
    }
    //点击marker获取经纬度（和地图上点的取值方式不一样，所以单独设置）
    AMap.event.addListener(placeSearch, "markerClick", markerAddGetLnla);
    function markerAddGetLnla(e) {
        document.getElementById("lonlat").value = e.data.location.lat + ',' + e.data.location.lng;
        addChoiseMark(e.data.location.lng,e.data.location.lat);
    }
    function addChoiseMark(lng,lat) {
        if(lng && lat){
            map.clearMap();
            var marker = new AMap.Marker({
//                icon: "__IMG__/pause.png",
                position: [lng, lat]
            });
            map.add(marker);
        }
    }
    /**
     * 点击地图获取经纬度
     */
    //为地图注册click事件获取鼠标点击出的经纬度坐标
    map.on('click', function(e) {
        document.getElementById("lonlat").value = e.lnglat.getLat() + ',' + e.lnglat.getLng();
        addChoiseMark(e.lnglat.getLng(),e.lnglat.getLat());
    });
</script>